package com.itheima.jieou;

import java.io.IOException;
import java.util.Properties;

/*
工厂类 用来生产对象
 */
public class Factory {
  private static  Properties prop = new Properties();
static {
    try {
        prop.load(ClassLoader.getSystemResourceAsStream("bean.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
    //工厂方法 用来生产对象的
    public static IStudentController getStudentController(){

        IStudentController controller=null;
        try {

            //IStudentController=com.itheima.jieou.StudentControllerImpl
            String className = prop.getProperty("IStudentController");
            //className  com.itheima.jieou.StudentControllerImpl
            //反射
            Class clazz = Class.forName(className);
            controller= (IStudentController) clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 不改代码的前提下 把实现类的对象给他换了
       // return new StudentControllerImpl();
        return controller;
    }

/*
    public  static  IStudentService  getIStudentService(){
        IStudentService service=null;
        try {

            //IStudentController=com.itheima.jieou.StudentControllerImpl
            String className = prop.getProperty("IStudentService");
            //className  com.itheima.jieou.StudentControllerImpl
            //反射
            Class clazz = Class.forName(className);
            service= (IStudentService) clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
return service;
    }*/
}
